<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
String path=request.getContextPath();
String uiPath=path+"/TopJUI";
%>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <!-- 避免IE使用兼容模式 -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <meta name="renderer" content="webkit">
    <!-- TopJUI框架样式 -->
    <link type="text/css" href="<%=uiPath %>/topjui/css/topjui.core.min.css" rel="stylesheet">
    <link type="text/css" href="<%=uiPath %>/topjui/themes/default/topjui.red.css" rel="stylesheet" id="dynamicTheme"/>
    <!-- FontAwesome字体图标 -->
    <link type="text/css" href="<%=uiPath %>/static/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet"/>
    <!-- layui框架样式 -->
    <link type="text/css" href="<%=uiPath %>/static/plugins/layui/css/layui.css" rel="stylesheet"/>
    <!-- jQuery相关引用 -->
    <script type="text/javascript" src="<%=uiPath %>/static/plugins/jquery/jquery.min.js"></script>
    <script type="text/javascript" src="<%=uiPath %>/static/plugins/jquery/jquery.cookie.js"></script>
    <!-- TopJUI框架配置 -->
    <script type="text/javascript" src="<%=uiPath %>/static/public/js/topjui.config.js"></script>
    <!-- TopJUI框架核心-->
    <script type="text/javascript" src="<%=uiPath %>/topjui/js/topjui.core.min.js"></script>
    <!-- TopJUI中文支持 -->
    <script type="text/javascript" src="<%=uiPath %>/topjui/js/locale/topjui.lang.zh_CN.js"></script>
    <!-- layui框架js -->
    <script type="text/javascript" src="<%=uiPath %>/static/plugins/layui/layui.js" charset="utf-8"></script>
</head>

<body>
<table id="productDg"></table>

<!-- 表格工具栏开始 -->
<div id="productDg-toolbar" class="topjui-toolbar"
     data-options="grid:{
           type:'datagrid',
           id:'productDg'
       }">
    <form id="queryForm">
        <input type="text" name="projectName" data-toggle="topjui-textbox"
               data-options="id:'projectName',prompt:'项目名称'">
        <input type="text" name="projectCode" data-toggle="topjui-textbox"
               data-options="id:'projectCode',prompt:'项目编号'">
        <a id="queryBtn" href="javascript:void(0)">查询</a>
    </form>
    <a id="add" href="javascript:void(0)">新增</a>
    <a id="edit" href="javascript:void(0)">编辑</a>
</div>
<!-- 表格工具栏结束 -->

<script>
    function progressFormatter(value, rowData, rowIndex) {
        var htmlstr = '<div id="p" data-toggle="topjui-progressbar progressbar" data-options="value:' + value + '" style="width: 398px; height: 26px;">';
        htmlstr += '<div class="progressbar-text" style="width: 398px; height: 26px; line-height: 26px;">' + value + '%</div>';
        htmlstr += '<div class="progressbar-value" style="width: ' + value + '%; height: 26px; line-height: 26px;">';
        htmlstr += '<div class="progressbar-text" style="width: 398px; height: 26px; line-height: 26px;">' + value + '%</div>';
        htmlstr += '</div>';
        htmlstr += '</div>';
        return htmlstr;
    }
    
    function messagePrompt(type) {
    	if (type == 'pname') {
    		var msg = '项目名称不能为空';
		}
    	if (type == 'ptime') {
    		var msg = '项目时间不能为空';
		}
    	if (type == 'paddress') {
    		var msg = '项目地址不能为空';
		}
    	if (type == 'xstid') {
    		var msg = '项目经理不能为空';
		}
    	if (type == 'sstid') {
    		var msg = '设计负责不能为空';
		}
    	if (type == 'jstid') {
    		var msg = '技术负责不能为空';
		}
    	if (type == 'cstid') {
    		var msg = '采购负责不能为空';
		}
    	if (type == 'cosid') {
    		var msg = '客户名称不能为空';
		}
    	if (type == 'contacts') {
    		var msg = '联系人不能为空';
		}
    	if (type == 'pcway') {
    		var msg = '联系方式不能为空';
		}
    	if (type == 'pjrtime1') {
    		var msg = '计划开工日期不能为空';
		}
    	if (type == 'pjrtime2') {
    		var msg = '计划开工日期不能小于项目日期';
		}
    	if (type == 'pjetime1') {
    		var msg = '计划完工日期不能为空';
		}
    	if (type == 'pjetime2') {
    		var msg = '计划完工日期不能小于开工日期';
		}
    	if (type == 'itemtype') {
    		var msg = '项目类型不能为空';
		}
    	if (type == 'money') {
    		var msg = '项目金额不能为空';
		}
    	if (type == 'fkway') {
    		var msg = '付款方式不能为空';
		}
    	if (type == 'jd') {
    		var msg = '项目进度不能为空';
		}
    	if (type == 'premarks') {
    		var msg = '备注说明不能为空';
		}
    	$.iMessager.show({
		    title: '操作提示',
		    msg: msg,
		    timeout: 5000,
		    showType: 'slide'
		});
    	return false;
	}
    
    $(function () {
        var productDg = {
            type: 'datagrid',
            id: 'productDg'
        };

        $("#productDg").iDatagrid({
            id: 'productDg',
            url: '${pageContext.request.contextPath}/hpf/queryAll.do',
            fitColumns: true,
            columns: [[
                {field: 'pid', title: 'pid', checkbox: true},
                {field: 'pnum', title: '项目编号', sortable: true},
                {field: 'pname', title: '项目名称', sortable: true},
                {field: 'ptime', title: '项目日期', sortable: true},
                {field: 'paddress', title: '项目地址', sortable: true},
                {field: 'xstid', title: '项目经理', sortable: true},
                {field: 'sstid', title: '设计负责', sortable: true},
                {field: 'jstid', title: '技术负责', sortable: true},
                {field: 'cstid', title: '采购负责', sortable: true},
                {field: 'pricid', title: '报价单', sortable: true},
                {field: 'cosid', title: '客户', sortable: true},
                {field: 'contacts', title: '联系人', sortable: true,},
                {field: 'pcway', title: '联系方式', sortable: true},
                {field: 'money', title: '资金', sortable: true},
                {field: 'pjrtime', title: '计划开工日期', sortable: true},
                {field: 'pjetime', title: '计划完工日期', sortable: true},
                {field: 'fkway', title: '付款方式', sortable: true},
                {field: 'jd', title: '项目进度', sortable: true},
                {field: 'premarks', title: '备注', sortable: true}
            ]]
        });

        /* 添加 */
        $("#add").iMenubutton({
            event: 'openDialog',
            iconCls: 'fa fa-plus',
            dialog: {
                id: 'projectAddDialog',
                height: 500,
                href: '${pageContext.request.contextPath}/hpf/projectButtonJump.do?type=1',
                buttonsGroup: [
                    {
                        text: '保存',
                        onClick: function() {
							var pname = $('#pname').val();
							if (pname == '') {
								return messagePrompt('pname');
							}
							var ptime = $('#ptime').val();
							if (ptime == '') {
								return messagePrompt('ptime');
							}
							var paddress = $('#paddress').val();
							if (paddress == '') {
								return messagePrompt('paddress');
							}
							var xstid = $('#xstid').val();
							if (xstid == '') {
								return messagePrompt('xstid');
							}
							var sstid = $('#sstid').val();
							if (sstid == '') {
								return messagePrompt('sstid');
							}
							var jstid = $('#jstid').val();
							if (jstid == '') {
								return messagePrompt('jstid');
							}
							var cstid = $('#cstid').val();
							if (cstid == '') {
								return messagePrompt('cstid');
							}
							var cosid = $('#cosid').val();
							if (cosid == '') {
								return messagePrompt('cosid');
							}
							var contacts = $('#contacts').val();
							if (contacts == '') {
								return messagePrompt('contacts');
							}
							var pcway = $('#pcway').val();
							if (pcway == '') {
								return messagePrompt('pcway');
							}
							var pjrtime = $('#pjrtime').val();
							if (pjrtime == '') {
								return messagePrompt('pjrtime1');
							}
							if (pjrtime < ptime) {
								return messagePrompt('pjrtime2');
							}
							var pjetime = $('#pjetime').val();
							if (pjetime == '') {
								return messagePrompt('pjetime1');
							}
							if (pjetime <= pjrtime) {
								return messagePrompt('pjetime2');
							}
							var itemtype = $('#itemtype').val();
							if (itemtype == '') {
								return messagePrompt('itemtype');
							}
							var money = $('#money').val();
							if (money == '') {
								return messagePrompt('money');
							}
							var fkway = $('#fkway').val();
							if (fkway == '') {
								return messagePrompt('fkway');
							}
							var jd = $('#jd').val();
							if (jd == '') {
								return messagePrompt('jd');
							}
							var premarks = $('#premarks').val();
							if (premarks == '') {
								return messagePrompt('premarks');
							}
				            var data = JSON.stringify({pname: pname, ptime: ptime, paddress: paddress, xstid: xstid, sstid: sstid, jstid: jstid, 
				            		cstid: cstid, cosid: cosid, contacts: contacts, pcway: pcway, pjrtime: pjrtime, 
				            		pjetime: pjetime, itemtype: itemtype, money: money, fkway: fkway, jd: jd, premarks: premarks});
				            $.ajax({
						        type: "POST",//方法类型
						        dataType: "json",//预期服务器返回的数据类型
						        url: '${pageContext.request.contextPath}/hpf/addProjectInfo.do',//url
						        data: data,
						        contentType:"application/json",
						        success: function (result) {
							        $('#projectAddDialog').dialog('close');
							        if (result.statusCode == 200) {
							        	$.iMessager.show({
							    		    title: '操作提示',
							    		    msg: '添加成功',
							    		    timeout: 5000,
							    		    showType: 'slide'
							    		});
							        } else {
							        	$.iMessager.show({
							    		    title: '操作提示',
							    		    msg: '添加失败',
							    		    timeout: 5000,
							    		    showType: 'slide'
							    		});
									}
						        },
						        error : function() {
						        	$.iMessager.show({
						    		    title: '操作提示',
						    		    msg: '添加异常',
						    		    timeout: 5000,
						    		    showType: 'slide'
						    		});
						        }
					        });
						}
                    }
                ]
            }
        });

        /* 编辑 */
        $("#edit").iMenubutton({
            event: 'openDialog',
            iconCls: 'fa fa-pencil',
            btnCls: 'topjui-btn',
            grid: productDg,
            dialog: {
                height: 500,
                id: 'projectEditDialog',
                href: '${pageContext.request.contextPath}/hpf/projectButtonJump.do?type=2',
                //url: '${pageContext.request.contextPath}/hpf/projectFindByID.do?pid={pid}',
                buttonsGroup: [
                    {
                        text: '更新',
                        url: _ctx + '/json/response/success.json',
                        iconCls: 'fa fa-save',
                        handler: 'ajaxForm',
                        btnCls: 'topjui-btn'
                    }
                ]
            }
        });

        /* 点击查询按钮 */
        $('#queryBtn').iMenubutton({
            event: 'query',
            iconCls: 'fa fa-search',
            btnCls: 'topjui-btn-danger',
            form: {id: 'queryForm'},
            grid: {type: 'datagrid', 
            	url: '${pageContext.request.contextPath}/hpf/queryAll.do',
            	'id': 'productDg'}
        });
    });

    // 自定义方法
    function myQuery() {
        // 提示信息
        $.iMessager.alert('自定义方法', '自定义方法被执行了！', 'messager-info');
        
        var checkedRows = $('#productDg').iDatagrid('getChecked');
        console.log(checkedRows);

        var selectedRow = $('#productDg').iDatagrid('getSelected');
        console.log(selectedRow);
        
        // 提交参数查询表格数据
        $('#productDg').iDatagrid('reload', {
            name: $('#name').iTextbox('getValue'),
            code: $('#code').iTextbox('getValue')
        });
    }
</script>
</body>
</html>